﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace FancyBattles.GameScreen
{
    class GameOverScreen : GameScreen
    {
        #region Atributes
        private Texture2D playAgainSelected;
        private Texture2D returnTitleSelected;
        private MenuEntry playAgain;
        private MenuEntry returnToTitle;
        private Texture2D gameOverBG;
        #endregion

        #region Properties
        #endregion

        #region Creators
        public GameOverScreen()
        {
            playAgain = new MenuEntry(playAgainSelected);
            returnToTitle = new MenuEntry(returnTitleSelected);
            playAgain.IsSelected = true;
        }
        #endregion

        #region Methods

        public override void LoadContent()
        {
            base.LoadContent();

            gameOverBG = ContentManager.Load<Texture2D>("Screens/END_GAME_MENU_NOTSELECTED");
            playAgainSelected = ContentManager.Load<Texture2D>("Screens/END_GAME_MENU_PLAYAGAIN_SELECTED");
            returnTitleSelected = ContentManager.Load<Texture2D>("Screens/END_GAME_MENU_RETURNTOTITLE_SELECTED");
        }

        public override void UnloadContent()
        {
            base.UnloadContent();
        }

        public override UpdateResponse Update(GameTime gameTime)
        {
            if (InputHandler.IsPause(PlayerIndex.One) || InputHandler.IsPause(PlayerIndex.Two))
            {
                return UpdateResponse.KEEP_STATE;
            }
            if (InputHandler.isMenuUp(PlayerIndex.One) || InputHandler.isMenuUp(PlayerIndex.Two) || InputHandler.isMenuDown(PlayerIndex.One) || InputHandler.isMenuDown(PlayerIndex.Two))
            {
                if (playAgain.IsSelected)
                {
                    playAgain.IsSelected = false;
                    returnToTitle.IsSelected = true;
                }
                else
                {
                    playAgain.IsSelected = true;
                    returnToTitle.IsSelected = false;
                }
            }
            if (InputHandler.isConfirm(PlayerIndex.One) && playAgain.IsSelected || InputHandler.isConfirm(PlayerIndex.Two) && playAgain.IsSelected)
            {
                //changes this to restart game
                return UpdateResponse.CLOSE_SCREEN;
            }
            if (InputHandler.isConfirm(PlayerIndex.One) && returnToTitle.IsSelected || InputHandler.isConfirm(PlayerIndex.Two) && returnToTitle.IsSelected)
            {
                return UpdateResponse.CLOSE_SCREEN;
            }
            return UpdateResponse.KEEP_STATE;
        }

        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            Rectangle fullscreen = new Rectangle(0, 0, 1280, 720);

            SpriteBatch.Begin();

            ScreenManager.SpriteBatch.Draw(CreditsScreen.creditsBG, fullscreen, Color.White);
            ScreenManager.SpriteBatch.Draw(gameOverBG, fullscreen, Color.White);
            if (playAgain.IsSelected)
            {
                ScreenManager.SpriteBatch.Draw(playAgainSelected, fullscreen, Color.White);
            }
            else
            {
                ScreenManager.SpriteBatch.Draw(returnTitleSelected, fullscreen, Color.White);
            }


            SpriteBatch.End();
            base.Draw(gameTime);
        }

        #endregion
    }
}
